# A.TNG

import os
import wsgiref.handlers

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'        
        # mashup table
        mtable = [{'title': '''The Javascript Programming Language - 1''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/sid/XNDA4MTkzMzI=/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_22dnhnk8d4' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Javascript Programming Language - 2''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/sid/XNDA4NDQ2NTI=/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_25gv4g2pcd' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Javascript Programming Language - 3''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/241560/Ob/1/Pt/2/sid/XMzUyOTE5Ng==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_33fgpkctc5' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Javascript Programming Language - 4''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/241560/Ob/1/Pt/3/sid/XMzUyOTE2OA==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_37gtczfvfz' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''Advanced Javascript - 1''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/237835/Ob/1/Pt/0/sid/XMzM0Nzc1Mg==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_40fzqftkfh' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''Advanced Javascript - 2''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/237835/Ob/1/Pt/1/sid/XMzM0Nzk5Ng==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_69dh9hvmdh' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''Advanced Javascript - 3''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/237835/Ob/1/Pt/2/sid/XMzM0NzkwOA==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_79dtt38zhk' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Theory of the DOM - 1''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/239116/Ob/1/Pt/0/sid/XMzQ3Nzg5Ng==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_86fb5kwbg5' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Theory of the DOM - 2''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/239116/Ob/1/Pt/1/sid/XMzQ3NzcxNg==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_97gmrqj375' frameborder='0' width='410' height='342'></iframe>'''
                   },
                   {'title': '''The Theory of the DOM - 3''',
                   'src_video': '''<embed src="http://player.youku.com/player.php/Type/Folder/Fid/239116/Ob/1/Pt/2/sid/XMzQ3NzkyNA==/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>''',
                   'src_ppt': '''<iframe src='http://docs.google.com/EmbedSlideshow?docid=ddcnpwgb_102hwcc3b7p' frameborder='0' width='410' height='342'></iframe>'''
                   },
                  ]
        if (self.request.query == ''):
            path = os.path.join(os.path.dirname(__file__), 'list.html')
            self.response.out.write(template.render(path, {'mtable': mtable}))
        else:
            path = os.path.join(os.path.dirname(__file__), 'main.html')
            try:
                id = int(self.request.get('id', 0))
            except ValueError:
                id = 0;
            # self.response.out.write('id='+str(id))
            try:
                tpl_value = mtable[id]
            except IndexError:
                tpl_value = mtable[0]
            self.response.out.write(template.render(path, tpl_value))
        

application = webapp.WSGIApplication([
                                      ('/jstutorial/', MainPage),
                                      ], debug=True)

def main():
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
    main()
